import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
	{
		path: '/',
		redirect: "index"
	},
	{
		path: "/login",
		component: () => import("../views/Login.vue")
	},
	{
		path: "/login_two",
		component: () => import("../views/Login_two.vue")
	},
	{
		path: "/reg",
		component: () => import("../views/reg.vue")
	},
	{
		path: '/index',
		component: () => import('../views/index.vue'),
		children: [
			{
				path: "/index",
				redirect: "home"
			},
			{
				path: "home",
				component: () => import("../views/home.vue")
			},
			{
				path: 'myShopList',
				component: () => import('../views/myShopList.vue')
			}
			,
			{
				path: 'shopCar',
				component: () => import('../views/shopCar.vue')
			}
			,
			{
				path: "orderSettle",
				component: () => import("../views/orderSettle")
			},
			{
				path: 'shopCar_',
				component: () => import('../views/shopCar_.vue')
			}
			,
			{
				path: 'my',
				component: () => import('../views/my.vue')
			}
		]
	}
	,
	{
		path: "/msg",
		name: "msg",
		component: () => import("../views/shopMsg.vue")
	}
	,
	{
		path: "/menuList",
		name: "menuList",
		component: () => import("../views/menuList.vue"),

	},
	{
		path: "/menuMsg",
		name: "menuMsg",
		component: () => import("../views/menuMsg.vue"),

	},
	{
		path: "/orderDeatailed",
		name: "orderDeatailed",
		component: () => import("../views/orderDetailed.vue")
	},
	{
		path: "/address",
		name: "address",
		component: () => import("../views/address.vue")
	},
	{
		path: "/Addddress",
		name: "Addaddress",
		component: () => import("../views/Addaddress.vue")
	},
	{
		path: '/shopSettled',
		name: "ShopSettled",
		component: () => import("../views/ShopSettled")
	},
	{
		path: '/password',
		name: "password",
		component: () => import("../views/password.vue")
	}
]

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})
//开始路由前置守卫
router.beforeEach((to, from, next) => {
	let token = sessionStorage.getItem("token");
	if (to.path == "/login" || to.path == "/login_two" || to.path == "/reg") {
		next();
	} else {
		if (token) {
			let a = true;
			if (a) {
				next()
			} else {
				next('/login')
			}
		} else {
			next('/login')
		}
	}
})
export default router
